<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"
    type="application/javascript"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.9/index.min.js"></script>
  <link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.9/theme-chalk/index.min.css" rel="stylesheet">
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
</head>

<body>
  <div id="app">
    <el-card>
      <el-form :model="form" ref="formRef":inline="true">
        <el-form-item label="标签名称" prop="tags">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="企业简称" prop="shortName">
          <el-input></el-input>
        </el-form-item>
        <el-form-item>
          <el-button>清除</el-button>
          <el-button type="primary">查询</el-button>
        </el-form-item>
      </el-form>
      <!--  v-model="state"  -->
      <el-tabs type="card" :value="state+''" @input="state = $event-0" @tab-click="onTabClick">
        <el-tab-pane label="启用" nam="1"></el-tab-pane>
        <el-tab-pane label="禁用" name="0"></el-tab-pane>
        <el-table :data="list" border style="width: 100%">
          <el-table-column type="index" width="50" label="序号">
          </el-table-column>
          <el-table-column label="企业全称">
          </el-table-column>
          <el-table-column label="企业简称">
          </el-table-column>
          <el-table-column label="标签">
          </el-table-column>
          <el-table-column label="状态">
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end">
          <el-pagination
          layout="prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="onPageChange">
          </el-pagination>
        </el-row>
      </el-tabs>
    </el-card>
  </div>
</body>
<script>
  if (!localStorage.token) location.href = './login.html'
  const request = axios.create({
    baseURL: 'http://hmmm-api.itheima.net/'
  })
  function getList (params) {
    return request({
      url: '/companys',
      method: 'get',
      params,
      headers: {
        Authorization: localStorage.token
      }
    })
  }
  new Vue({
    el: '#app',
    data () {
      return {
        list: [], // 列表
        form: {    // 搜索
          tags: undefined,
          shortName: undefined
        },
        state: '1',
        page: {    // 分页
          page: 1,
          pagesize: 5,
          total: 0
        }
      }
    },
    created () {
      this.getList()
    },
    methods: {
      async getList(){
        let {data:{counts,items}} = await getList({
          ...this.form,
          state:this.state,
          ...this.page
        })
        this.list = items
        this.page.total = counts
      },
      onTabClick(){

      },
      onClear(){
        // this.$ref.formRef =
      },
      onPageChange(val){
        this.page.page = val
        this,getList()
      }
    },
  })
</script>
</html>
